﻿<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
	xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout">
<head th:include="inc/home::header">
</head>
<meta charset="utf-8" />
<script type="text/javascript" th:src="@{/home/js/public.js}"></script>
<style type="text/css">
  	body,html{background:#fff;overflow-y:auto;padding:0 5px}
</style>

<script th:inline="javascript"> 
/*<![CDATA[*/  
	    	$(function(){
			   $('#category-add').on('click', function(e) {
			        e.preventDefault();
			        top.$.Zebra_Dialog({
			            source: {'iframe': {
			            	'id':'categoryAdd1',
			                'src':'category-add.html',
			                'height':100,
			            }},
			            width:440,
			            title:'新增计划类别',
			            buttons: [{caption: '保存', callback: function() { 
			            	
			           /*  	  var validate=top.document.getElementById("categoryAdd1").contentWindow.getData();
		            		  if(!validate){
		            			 return false;
		            		 } */
			            	   var data= top.document.getElementById("categoryAdd1").contentWindow.getDataJson("categoryAdd");
			           		    var obj = JSON.stringify(data);
			       		     	AjaxWebTableInfo("/planType/saveOrUpdate",data);
			                  }}]
			        });
			    });
			   
			   $('#category-edit').on('click', function(e) {
					e.preventDefault();
					if($('input[name="select_item"]:checked').length==1){
						var checkBoxs= $('input[name="select_item"]:checked').parent();
						var id=checkBoxs.parent().parent().find("[name='id']").text();
						var diag = new top.$.Zebra_Dialog({
							source : {
								'iframe' : {
									'id':'categoryEdit',
									'src' : '/planType/category-edit.html?id='+id,
									'height':100,
								}
							},
							  width:440,
							title : '编辑计划类别',
						    buttons:  [
						               {caption: '保存', callback: function() { 
						            	 	var validate=top.document.getElementById("categoryEdit").contentWindow.getData();
						            		  if(!validate){
						            			 return false;
						            		 }
						            	    var data= top.document.getElementById("categoryEdit").contentWindow.getDataJson("categoryAdd");
						           		    var obj = JSON.stringify(data);
						       		     	AjaxWebTableInfo("/planType/saveOrUpdate",data);
						                  }}
				                        ]
						});
						
						
						
					}else{
						top.$.Zebra_Dialog('<div class="prompt"><div class="warning-icon"></div><div class="success-title">请选中一行!</div></div>', {
					            'title':'提示',
					            'buttons':['确定']
					         });
					}
				
				});
				
				$('#category-dele').on('click', function(e) {
					e.preventDefault();
					var checkBoxs= $('input[name="select_item"]:checked').parent();
					var ids=checkBoxs.parent().parent().find("[name='id']");
				    var  id="";
		  		   for (var i=0;i<ids.length;i++)
					{
		  				if(i<ids.length-1){
		  					id += $(ids[i]).text()+",";
		  				}else{
		  					id += $(ids[i]).text();
		  				}
					} 
		  		   
		  		 $.ajax({
				     type: "post",
				     dataType: "json",
				     url:"/planType/dele" ,
				     data:{id:id},
				     success: function (data, status) {
				    	 $.Zebra_Dialog('<div class="prompt"><div class="success-icon"></div><div class="success-title">删除成功!</div></div>', {
					            'title':'提示',
					            'buttons':['确定'] 
					         });
				    	 location.reload();
				     },
				     error: function (data) {
				    	 $.Zebra_Dialog('<div class="prompt"><div class="error-icon"></div><div class="success-title">删除失败!</div></div>', {
					            'title':'提示',
					            'buttons':['确定']
					         });
				     	 location.reload();
				     }
				 });
		  		   
				 });  
			   
	    	})
	    	
	    	
	    	
	function AjaxWebTableInfo(url , obj){
		 $.ajax({
		     type: "post",
		     dataType: "json",
		     url: url,
		     data:obj,
		     success: function (data, status) {
		 /*    	 $.Zebra_Dialog('<div class="prompt"><div class="success-icon"></div><div class="success-title">保存成功!</div></div>', {
			            'title':'提示',
			            'buttons':['确定']
			         }); */
		    	 location.reload();
		     },
		     error: function (data) {
		    	 $.Zebra_Dialog('<div class="prompt"><div class="error-icon"></div><div class="success-title">保存失败!</div></div>', {
			            'title':'提示',
			            'buttons':['确定']
			         });
		     }
		 });	
	}	    	
	    	
	    	
	/*]]>*/  
	
</script>
	<body>
	    <div class="bookmarks">
			<!--内容开始-->
	    	 <div class="table-tool">
	       	  	 <div class="table-tool-btn">
	       	  	 	<div class="tool-btn" id="category-add"><span class="add-icon"></span><a>新增</a></div>
	       	  	 	<div class="tool-btn" id="category-edit"><span class="edit-icon"    ></span><a>编辑</a></div>
	       	  	 	<div class="tool-btn" id="category-dele" ><span class="del-icon"     ></span><a>删除</a></div>
	          	 </div>
	          </div>
	          <div class="table-head">
          	   <table width="100%" align="center" cellpadding="0" cellspacing="0" border="0">
          		<thead>
	          		<tr>
	          			<td width="8%"><input type="checkbox" /></td>
	          			<td style="display: none">id</td>
	          			<td width="92%">计划类别</td>
	          		</tr>
          		</thead>
          		<tbody>
	          	
	          			<tr th:each="row,iterStat : ${rows}">
							<td ><input type="checkbox" name="select_item" /></td>
							<td  name="id" th:text="${row.id}" style="display: none">id</td>
							<td th:text="${row.typeName}">计划类别</td>
						</tr>
          		</tbody>
          	   </table>
            </div>
            <!--内容结束-->
           </div>
	</body>
</html>
